/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mattespill.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import mattespill.Oversikt;

/**
 *
 * @author havardaxelsen
 */
public class GUIAdminpanel extends JPanel{
    
    
    private JPanel pgi;
    private Color c             = new Color(255,255,255, 150);
    private Color t             = new Color(255,255,255, 0);
    private Oversikt o;
    private Adminpanel p;
    
    public GUIAdminpanel(Oversikt o) {
        setLayout(new GridLayout(1,1));
        this.o = o;
        p =  new Adminpanel(o);
        this.setBackground(t);
        add(p);
    }
    
    
    
}

class Adminpanel extends JPanel{
    
    private JLabel admin    = new JLabel("Adminpanel");
    private Knappelytter k;
    private Ppanel p;
    private Oversikt o;
   
    
    public Adminpanel(Oversikt o){
        this.o     = o;
        k          = new Knappelytter();
        p          = new Ppanel(k);

        setLayout(new BorderLayout());
        admin.setBorder(BorderFactory.createEmptyBorder(10,270,0,0));
       // setBackground(new Color(255,255,255, 150));
        admin.setFont(new Font("Comic Sans MS",Font.BOLD,22));
        add(admin, BorderLayout.NORTH);
        add(p, BorderLayout.SOUTH);
        
    }
        
    
    
        private class Knappelytter implements ActionListener{

            public void actionPerformed(ActionEvent h){


            Knapp k = (Knapp)h.getSource();
            
            if(k.getText().equals("Legg til bruker")){
                
                GUILeggTilBruker ltb = new GUILeggTilBruker(1, o);
                fix(ltb);
                
            }
            else if(k.getText().equals("Slett bruker")){
                GUISlettBruker g = new GUISlettBruker(o);
                fix(g);
                
            }
            else if(k.getText().equals("Hent status")){
                
                GUIGetStatus g = new GUIGetStatus(o);
                fix(g);
                
            }
            else if(k.getText().equals("Logg ut")){
                GUILoggInn g = new GUILoggInn();
                fix(g);


            }
            else if(k.getText().equals("Nullstill highscore")){
                if(o.nullstillHighscore()){
                    JOptionPane.showMessageDialog(null,"Nullstilling OK!");
                }

            }    
}
         
         private void fix(JPanel j){
            JPanel mainPanel = (JPanel)getParent();
            mainPanel.removeAll(); // dette is the sub-panel
            mainPanel.add(j);
            mainPanel.repaint();
            mainPanel.revalidate();
            j.repaint();
            j.revalidate();
         }
        
    }
}
class Ppanel extends JPanel{

    private Knapp leggtil = new Knapp("Legg til bruker");
    private Knapp slett   = new Knapp ("Slett bruker");
    private Knapp status  = new Knapp("Hent status");
    private Knapp meny    = new Knapp("Logg ut");
    private Knapp sletthighscore    = new Knapp("Nullstill highscore");

    public Ppanel(ActionListener a) {
        
        setBorder(BorderFactory.createEmptyBorder(30,10,30,10));
       // setBackground(new Color(255,255,255, 0));
        setLayout(new GridLayout(1,5));
        leggtil.addActionListener(a);
        slett.addActionListener(a);
        status.addActionListener(a);
        meny.addActionListener(a);
        sletthighscore.addActionListener(a);
        add(status);
        add(leggtil);
        add(slett);
        add(sletthighscore);
        add(meny);


    }


}

